package com.yanqu.road.server.cmd.activity.huashigang;

import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.huashigang.HuaShiGangProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.cross.battle.HuaShiGangMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.Protocol;

/**
 * @author ：zfr
 * @date ：2021/2/1 18:20
 */
@Cmd(code = Protocol.C2_HUA_SHI_GANG_CHANGE_TRANSPORT, desc = "花石纲跨服更换交通工具")
public class CrossChangeTransportCmd extends CrossCommand {
    private int activityId;
    private int transportId;
    private HuaShiGangProto.ChangeTransportRespMsg.Builder builder;
    private long playerId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        HuaShiGangProto.CrossChangeTransportReqMsg msg = HuaShiGangProto.CrossChangeTransportReqMsg.parseFrom(packet.getBytes());
        activityId = msg.getActivityId();
        transportId = msg.getTransportId();
        builder = HuaShiGangProto.ChangeTransportRespMsg.newBuilder();
        playerId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        HuaShiGangMgr.changeTransport(activityId, serverId, playerId, transportId, builder);
    }

    @Override
    public void sendData() {
        MessageHelper.sendPacket(serverId, playerId, YanQuMessageUtils.buildMessage(ClientProtocol.U_HUA_SHI_GANG_CHANGE_TRANSPORT, builder));
    }
}
